//
// Created by mabinjie on 2024/10/29.
//

#ifndef VERIFICATION_HPP
#define VERIFICATION_HPP
#include <cstdint>

#include "common/types.h"
#include "protocol/message/jtt808_body.hpp"

namespace protocol::terminal {

class Verification final : public jtt808_body {
public:
    uint8_t auth_code_length_;
    common::Container<char> *auth_code_;
    common::Bytes<15> imei_;
    common::Bytes<20> version_;

    IMPLEMENT_SIZEABLE(auth_code_length_, auth_code_, imei_, version_)
    IMPLEMENT_TOSTRING(message_id_, auth_code_length_, auth_code_, imei_, version_)

    Verification() : jtt808_body(0x0102) {}
    Verification(const uint8_t auth_code_length, const common::Container<char>& auth_code,
        const common::Bytes<15>& imei, const common::Bytes<20>& version) : jtt808_body(0x0102), auth_code_length_(auth_code_length),
        auth_code_(new common::Container(auth_code)), imei_(imei), version_(version) {}

    Verification(const Verification &other) = default;

    Verification(Verification &&other) noexcept = default;

    Verification & operator=(const Verification &other) = default;

    Verification & operator=(Verification &&other) noexcept = default;

    ~Verification() override = default;

    void serialize(common::MessagePackWriter &writer) override {
        writer.writeByte(auth_code_length_);
        auth_code_->serialize(writer);
        imei_.serialize(writer);
        version_.serialize(writer);
    }

    void deserialize(common::MessagePackReader &reader) override {
        reader.readByte(auth_code_length_);
        auth_code_ = new common::Container<char>(auth_code_length_);
        auth_code_->deserialize(reader);
        imei_.deserialize(reader);
        version_.deserialize(reader);
    }
};

}

#endif //VERIFICATION_HPP
